<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  "use strict"; {
    const arr1 = [1, 2, 3, 4, 5],
      arr2 = [5, 6, 7, 8, 9],
      _arr1Set = new Set(arr1),
      _arr2Set = new Set(arr2);

    // 交集
    let intersection = arr1.filter(item => _arr2Set.has(item));
    console.log(intersection);
    // 并集
    let union = Array.from(new Set([...arr1, ...arr2]));
    console.log(union);
    // 补集 两个数组各自没有的集合
    let complement = [...arr1.filter(item => !_arr2Set.has(item)), ...arr2.filter(item => !_arr1Set.has(item))];
    // 差集 数组arr1相对于arr2所没有的
    let diff = arr1.filter(item => !_arr2Set.has(item))
  };
</script>

</html>